import storage from 'store'
import cloneDeep from 'lodash.clonedeep'
let TABLE_FILTER = 'table-filter'

function getTable(){
    let data = storage.get(TABLE_FILTER)
    if(data){
        return JSON.parse(data)
    }else{
        return {}
    }
}

const user = {
  state: {
    tableColumns: getTable(),
  },

  mutations: {
    SET_Table: (state, tableColumns) => {
      state.tableColumns = tableColumns
    },
  },

  actions: {
    // 登录
    ChangeTable({
        commit,
        state
    }, a_data){
        let tableColumns = cloneDeep(state.tableColumns)
        let { key, data } = a_data
        tableColumns[key] = data
        storage.set( TABLE_FILTER, JSON.stringify(tableColumns))
        commit('SET_Table', tableColumns)
    }
  }
}

export default user